package com.mark.mall.admin.platform.controller;


import com.github.pagehelper.PageInfo;
import com.mark.mall.admin.platform.dto.PageParamDTO;
import com.mark.mall.admin.platform.dto.ProviderDTO;
import com.mark.mall.admin.platform.dto.ProviderSelectDTO;
import com.mark.mall.admin.platform.dto.param.ProviderAddParam;
import com.mark.mall.admin.platform.dto.param.ProviderUpdateParam;
import com.mark.mall.common.resultBean.R;
import com.mark.mall.admin.platform.service.ProviderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-02-28
 */
@RestController
@RequestMapping("/admin/provider")
@Api(tags = "后台供应商模块")
@RequiredArgsConstructor
public class ProviderController {

    private final ProviderService providerService;

    @ApiOperation(value = "供应商列表", httpMethod = "GET")
    @GetMapping("list")
    public R<PageInfo<ProviderDTO>> providerPageInfo(PageParamDTO pageParamDTO, String providerName) {
        return providerService.providerPageInfo(pageParamDTO, providerName);
    }

    @ApiOperation(value = "新增供应商", httpMethod = "POST")
    @PostMapping("add")
    public R<Boolean> addProvider(@RequestBody @Valid ProviderAddParam param) {
        return providerService.addProvider(param);
    }

    @ApiOperation(value = "删除供应商(可批量操作)", httpMethod = "POST")
    @PostMapping("del")
    public R<Boolean> delProvider(String ids) {
        return providerService.delProvider(ids);
    }

    @ApiOperation(value = "修改供应商", httpMethod = "POST")
    @PostMapping("update")
    public R<Boolean> updateProvider(@RequestBody @Valid ProviderUpdateParam param) {
        return providerService.updateProvider(param);
    }

    @ApiOperation(value = "下拉获取供应商列表", httpMethod = "GET")
    @GetMapping("selectList")
    public R<List<ProviderSelectDTO>> selectList() {
        return providerService.selectList();
    }
}
